import Layout from '@/components/Layout/index.vue'

// 遍历后台传来的路由字符串，转换为组件对象
export function filterAsyncRouter(asyncRouterMap: Array<any>) {
  const rst: Array<any> = []
  traveralRouter(asyncRouterMap)
  function traveralRouter(routers: Array<any>) {
    routers.forEach((item) => {
      if (item.component && item.component === 'Layout') {
        item.component = Layout
      } else {
        item.component = loadView(item.path)
      }
      if (item.children != null && item.children && item.children.length) {
        traveralRouter(item.children)
      }
      rst.push(item)
    })
  }
  return rst
}

export const loadView = (view: string) => {
  // 路由懒加载
  return () => import(`@/views/line-info/line/index.vue`)
  // return () => import(`@/views/science/construction/high-end-platform/index.vue`)
}
